import service from "../utils/request.js";
import qs from "qs" 
/**
 * This function logs in a user by sending a POST request to the "/login" endpoint with the provided data.
 * @param {Object} data - The data to be sent in the request body.
 * @returns {Promise} - A Promise that resolves to the response from the server.
 */
export const login = (data) => {
    return service({
        url: "login", // Endpoint for the login request
        method: "post", // HTTP method for the request
        // data:qs.stringify(data), // Request body data
        data
    });
}


/**
 * Registers a user by sending a POST request to the "/register" endpoint.
 * 
 * @param {Object} data - The data to be sent in the request body.
 * @returns {Promise} - A promise that resolves to the response from the server.
 */
export const register = (data) => {
    return service({
        url: "/register",
        method: "post",
        data,
    });
}


/**
 * This function makes a POST request to the /logout endpoint
 * using a service function.
 *
 * @returns {Promise} A promise that resolves to the response of the request.
 */
export const logout = () => {
    return service({
        url: "/logout",
        method: "post",
    });
}

/**
 * Retrieves user information from the server.
 * 
 * @param {Object} data - The data to send in the request.
 * @returns {Promise} A Promise that resolves with the user information.
 */
export const getPermissionMenu = (data) => {
    // Send a POST request to the "/usersInfo" endpoint with the provided data
    return service({
        url: "/getPermissionMenu",
        method: "post",
        data
    });
}
